home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Tutorial ƒ / Assignment5 (hitTask).p < prev    next >
Text File  |  1995-01-16  |  2KB  |  84 lines

  1. program Assignment5;
  2.     uses
  3. {$ifc UNDEFINED THINK_PASCAL}
  4.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, OSEvents, {}
  5. {$endc}
  6.         SAT;
  7.  
  8.     const
  9.         kSpeed = 5;
  10.     var
  11.         ignore: SpritePtr;
  12.         direction: Integer;
  13.         theSound: Handle;
  14.  
  15.     procedure HandleSprite (me: SpritePtr);
  16.     begin
  17.         GetMouse(me^.position);
  18.     end; {HandleSprite}
  19.  
  20.     procedure SetupSprite (me: SpritePtr);
  21.     begin
  22.         me^.task := @HandleSprite;
  23.         me^.face := SATGetFace(128);
  24.         SetRect(me^.hotRect, 0, 0, 32, 32);
  25.     end; {SetupSprite}
  26.  
  27.     procedure SetupTarget (me: SpritePtr);
  28.     forward;
  29.  
  30.     procedure HandleTarget (me: SpritePtr);
  31.     begin
  32.         me^.position.h := me^.position.h + direction;
  33.         if me^.position.h <= 0 then
  34.             direction := kSpeed;
  35.         if me^.position.h >= 200 then
  36.             direction := -kSpeed;
  37.     end; {HandleTarget}
  38.  
  39.     procedure HitTarget (me, him: SpritePtr);
  40.     begin
  41.         if him^.task = @HandleSprite then {Chack what we hit!}
  42.             begin
  43.                 me^.task := nil;
  44.                 ignore := SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), @SetupTarget);
  45. {We could also re-use the old sprite for a new one, if we like.}
  46.                 SATSoundPlay(theSound, 1, true);
  47.             end;
  48.     end; {HandleTarget}
  49.  
  50.     procedure SetupTarget (me: SpritePtr);
  51.     begin
  52.         me^.task := @HandleTarget;
  53.         me^.hitTask := @HitTarget;
  54.         me^.face := SATGetFace(129);
  55.         SetRect(me^.hotRect, 0, 0, 32, 32);
  56.         direction := kSpeed;
  57.     end; {SetupTarget}
  58.  
  59.     const
  60.         kTicksPerFrame = 2;
  61.     var
  62.         t: Longint;
  63.  
  64. begin
  65. {$ifc UNDEFINED THINK_PASCAL}
  66.     SATInitToolbox;
  67. {$endc}
  68.  
  69.     SATConfigure(false, kVPositionSort, kForwardCollision, 32);
  70.     SATInit(128, 129, 478, 302);
  71.     ignore := SATNewSprite(0, 200, 200, @SetupSprite);
  72.     ignore := SATNewSprite(0, 0, SATRand(gSAT.offSizeV), @SetupTarget);
  73.     theSound := SATGetNamedSound('TestSound');
  74.     HideCursor;
  75.     while not Button do
  76.         begin
  77.             t := TickCount;
  78.             SATRun(true);
  79.             while TickCount < t + kTicksPerFrame do
  80.                 ;
  81.         end;
  82.     ShowCursor;
  83.     SATSoundShutup;
  84. end.